package handle

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"yk1/api/basic/config"
	__ "yk1/api/basic/proto"
	"yk1/api/request"
)

func DeliveryAdd(c *gin.Context) {
	var req request.DeliveryAddReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "参数验证失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Client.DeliveryAdd(c, &__.DeliveryAddReq{
		RiderId:        int64(req.RiderId),
		TrackingNumber: req.TrackingNumber,
		CabinetId:      int64(req.CabinetId),
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "添加失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "添加成功",
		"data": r,
	})

}

func DeliveryList(c *gin.Context) {
	var req request.DeliveryListReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "参数验证失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Client.DeliveryList(c, &__.DeliveryListReq{
		Page:     req.Page,
		PageSize: req.PageSize,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "列表展示失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "列表展示成功",
		"data": r,
	})

}

func DeliveryDetails(c *gin.Context) {
	var req request.DeliveryDetailsReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "参数验证失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Client.DeliveryDetails(c, &__.DeliveryDetailsReq{
		Id: int64(req.Id),
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "详情展示失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "详情展示成功",
		"data": r,
	})

}
